// tabs
const { BaseBehavior, COMPONENT_OPTIONS } = require('../../mixins/component');
Component({
    behaviors: [BaseBehavior],
    options: {
        ...COMPONENT_OPTIONS,
        pureDataPattern: /^_/,
    },
    properties: {
        tabList: { type: Array, value: [] },
        tabKey: { type: String, value: 'title' },
        tabContentHeight: { type: Number, value: 400 },
        tabActiveTextColor: { type: String, value: 'inheirt' },
        tabInactiveTextColor: { type: String, value: 'rgba(125, 125, 131, 1)' },
        tabBackgroundColor: { type: String, value: 'transparent' },
        activeTab: { type: Number, value: 0 },
        swipeable: { type: Boolean, value: true },
        animation: { type: Boolean, value: true },
        duration: { type: Number, value: 500 },
    },
    data: {
        currentView: 0,
    },
    observers: {
        activeTab: function (_activeTab) {
            const { tabList } = this.data;
            var len = tabList.length;
            if (len === 0) return;
            var currentView = _activeTab - 1;
            if (currentView < 0) currentView = 0;
            if (currentView > len - 1) currentView = len - 1;
            this.setData({ currentView: currentView });
        }
    },
    methods: {
        handleTabClick: function handleTabClick(e) {
            var index = e.currentTarget.dataset.index;
            this.setData({ activeTab: index });
            this.triggerEvent('tabclick', { index: index });
        },
        handleSwiperChange: function handleSwiperChange(e) {
            var index = e.detail.current;
            this.setData({ activeTab: index });
            this.triggerEvent('change', { index: index });
        }
    }
})